/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package embeddedpaint.user_interface.tools;

import embeddedpaint.model.layers.ALayer;
import embeddedpaint.model.layers.LayerManager;
import java.awt.Component;
import javax.swing.JOptionPane;

public class ToolsManageLayer
{

    public static final int     M_MINIMAL_NUMBER_TO_MULTI_LAYER   = 1;
    
    private static final String M_MESSAGE_DELETE_LAYER_TEXT       = "Delete the layer : ";
    private static final String M_MESSAGE_DELETE_LAYER_TITLE      = "Delete Layer";
    private static final String M_MESSAGE_RENAME_LAYER_TEXT       = "Enter the new name :";
    private static final String M_MESSAGE_RENAME_LAYER_TITLE      = "Rename";
    private static final String M_ERROR_MESSAGE_MERGE_LAYER_TEXT  = "Sorry, but you can't mix a merge these layers.\nPlease remove selected text Layer.";
    private static final String M_ERROR_MESSAGE_MERGE_LAYER_TITLE = "Merge forbiden";

    public static void deleteLayer (LayerManager manager, Component application, ALayer layer)
    {
        int result = JOptionPane.showConfirmDialog(application,
                M_MESSAGE_DELETE_LAYER_TEXT + layer.getM_name() + " ?", M_MESSAGE_DELETE_LAYER_TITLE,
                JOptionPane.YES_NO_OPTION);
        
        if (result == JOptionPane.YES_OPTION)
        {
            manager.remove(layer);
        }
    }

    public static void renameLayer (LayerManager manager, Component application, ALayer layer)
    {
        String result = JOptionPane.showInputDialog(application, M_MESSAGE_RENAME_LAYER_TEXT, M_MESSAGE_RENAME_LAYER_TITLE, JOptionPane.QUESTION_MESSAGE);
        
        if (result != null)
        {
            layer.setM_name(result);
            manager.updateObservers();
        }
    }

    public static void mergeLayerImage (LayerManager manager, Component application)
    {
        if (!manager.selectedLayerIsOnlyLayerImage())
        {
            JOptionPane.showMessageDialog(application, M_ERROR_MESSAGE_MERGE_LAYER_TEXT, M_ERROR_MESSAGE_MERGE_LAYER_TITLE, JOptionPane.ERROR_MESSAGE);
        }
        else
        {
            manager.mergeSelectedLayers();
        }
    }
}
